﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace DAL
{
    public class Teacher
    {
        public static string connectionString = ConfigurationManager.ConnectionStrings["projectbConnection"].ToString();
        public List<Model.Teacher> select()
        {
            DataSet ds = new DataSet();
            List<Model.Teacher> teacher = new List<Model.Teacher>();
            using (SqlConnection conn=new SqlConnection(connectionString))
            {   
                try
                {   
                    conn.Open();
                    SqlCommand comm = new SqlCommand("select TeacherName, TeacherId from Teacher", conn);
                    SqlDataAdapter da =new SqlDataAdapter(comm);
                    da.Fill(ds);
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        Model.Teacher t = new Model.Teacher { 
                        TeacherName=row[0].ToString(),
                        TeacherId=Convert.ToInt32(row[1])
                        };
                        teacher.Add(t);
                    }
                    return teacher;
                }
                catch (SqlException e)
                {   
                    throw new Exception(e.Message);
                }
            }        
        }
        
    }
    
}
